/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.biblioteca8a.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.itschapala.dsw2.biblioteca8a.DAO.CategoriaDaoLocal;
import mx.itschapala.dsw2.biblioteca8a.enumeracion.EstadoServicio;
import mx.itschapala.dsw2.biblioteca8a.modelo.Categoria;

/**
 *
 * @author z
 */
@Stateless
public class CategoriaBl implements CategoriaBlLocal {
    @EJB
    private CategoriaDaoLocal categoriaFacade;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

     @Override
    public EstadoServicio register(Categoria category) {
        if(categoriaFacade.findDuplicity(category)){
           return EstadoServicio.INCOMPLETE;
           
          } else{
          categoriaFacade.create(category);
          return EstadoServicio.COMPLETE;
        } 
       }
    @Override
    public EstadoServicio Modify(Categoria category) {
        if(category.getId()== null ||  categoriaFacade.find(category.getId())==null){
           return EstadoServicio.INCOMPLETE;
           
          } else{
          categoriaFacade.find(category);
          return EstadoServicio.COMPLETE;
    }
    }

    @Override
    public EstadoServicio delete(Categoria category) {
         if(category.getId()== null ||  categoriaFacade.find(category.getId())==null){
           return EstadoServicio.INCOMPLETE;
           
          } else{
          categoriaFacade.remove(category);
          return EstadoServicio.COMPLETE;
    }
    }

    @Override
    public Categoria findById(Integer id) {
        return categoriaFacade.find(id);
    }
    public List <Categoria> getAll (){
        return categoriaFacade.findAll();
    }
}

